package edu.sctu.zhoumengxue.day201506.day20150614.iopractice;

import java.io.*;

/**
 * Created by user12 on 2015/6/14.
 */
public class Reader {
    public void isInputStream(){
        int count = 0;
        int countbyte;
        byte[] buffer = new byte[1024];

        try {
            FileInputStream input = new FileInputStream(new File("D://zhou.jpg"));
            FileOutputStream out = new FileOutputStream(new File("D://图片//125.jpg"));
            try {
                while ((countbyte = input.read(buffer))!=-1){
                    count +=countbyte;
                    out.write(buffer,0,countbyte);
                }
                System.out.println(count);
            } catch (IOException e) {
                try {
                    out.close();
                    input.close();

                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void fileInput(){
        char[] cha = new char[1024];
        byte[] bytes =new byte[1024] ;
        try {
            FileReader in = new FileReader(new File("D://xh.txt"));
            try {
                FileWriter out = new FileWriter(new File("D://sg.txt"));

                while ((in.read(cha,0,cha.length))!=-1)
                {

                    for (int i = 0; i < cha.length; i++) {
                        bytes[i] = (byte) cha[i];
                        out.write(cha,0,i);

                    }

                    System.out.println(new String(cha));
                    System.out.println(bytes);

                }


                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

}
